package com.my.study.excel.demo;

import cn.hutool.core.util.NumberUtil;
import com.my.study.excel.export.BaseExcelExportService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

@Service
public class TestExcelExportDemo extends BaseExcelExportService {

    /*@Autowired
    private TestMapper testMapper;*/

    public void export(HttpServletResponse response, Map<String, String> map, String fileName) {
        this.exportData(response, map, fileName);
    }

    @Override
    public long getTotalDataNum(Map<String, String> map) {
        /*Test test = BeanUtil.toBean(map,Test.class);
        return testMapper.totalCount(test);*/
        return TestExcelConstant.TOTAL_DATA_NUM;
    }

    @Override
    public long getSheetRowNum() {
        return TestExcelConstant.SHEET_ROW_NUM;
    }

    @Override
    public long writeNum() {
        return TestExcelConstant.WRITE_NUM;
    }

    @Override
    public List<List<String>> setTableHead() {
        List<List<String>> heads = new ArrayList<>();
        heads.add(Collections.singletonList("id"));
        heads.add(Collections.singletonList("姓名"));
        heads.add(Collections.singletonList("年龄"));
        heads.add(Collections.singletonList("生日"));
        return heads;
    }

    @Override
    public List<List<String>> queryWriteData(Map map) {
        List<List<String>> dataList = new ArrayList<>();
        /*Test test = BeanUtil.toBean(map,Test.class);
        PageHelper.startPage(Integer.parseInt(String.valueOf(map.get("curPage"))) , Integer.parseInt(String.valueOf(map.get("pageSize"))));
        List<Test> tests = testMapper.queryTestList(test);
        if(CollectionUtils.isEmpty(tests)){
            return dataList;
        }
        tests.forEach(testTemp -> {
            dataList.add(Collections.singletonList(testTemp.getId()));
            dataList.add(Collections.singletonList(testTemp.getName()));
            dataList.add(Collections.singletonList(String.valueOf(testTemp.getAge())));
            dataList.add(Collections.singletonList(DateFormatUtils.format(testTemp.getBirthDay(),"yyyy-MM-dd HH:mm:ss")));
        });*/
        for (int i = 0; i < TestExcelConstant.WRITE_NUM; i++) {
            dataList.add(Arrays.asList(
                    UUID.randomUUID().toString(),
                    "test" + i,
                    String.valueOf(NumberUtil.add(i, 10)),
                    DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"))
            );
        }
        return dataList;
    }
}
